package com.example.demo.ServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.example.demo.Entity.Student;
import com.example.demo.Mapper.StudentMapper;
import com.example.demo.Service.StudentService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

// 对接口进行实现，service的impl是把mapper和service进行整合的文件 封装Service层的业务逻辑有利于业务逻辑的独立性和重复利用性
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public PageInfo<Student> findAllStudent(Integer pageIndex, Integer pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        List<Student> lists = studentMapper.findAllStudent();
        PageInfo<Student> info = new PageInfo<Student>(lists);
        return info;
    }

    @Override
    public Integer addStudentInfo(Student student) {
        return studentMapper.addStudentInfo(student);
    }

    @Override
    public Student findStudentByID(Integer stuid) {
        return studentMapper.findStudentByID(stuid);
    }

    @Override
    public Integer updateStudentID(Student student) {
        return studentMapper.updateStudentID(student);
    }

    @Override
    public Integer deleteStudentInfo(Integer stuid) {
        return studentMapper.deleteStudentInfo(stuid);
    }

    @Override
    public PageInfo<Student> findStudentByClsIDStuName(Integer pageIndex,Integer pageSize,Integer clsid, String stu_name) {
        PageHelper.startPage(pageIndex,pageSize);
        List<Student> lists = studentMapper.findStudentByClsIDStuName(clsid,stu_name);
        PageInfo<Student> info = new PageInfo<Student>(lists);
        return info;
    }

    @Override
    public PageInfo<Student> findStudentByStuName(Integer pageIndex,Integer pageSize,String stu_name) {
        PageHelper.startPage(pageIndex,pageSize);
        List<Student> lists = studentMapper.findStudentByStuName(stu_name);
        PageInfo<Student> info = new PageInfo<Student>(lists);
        return info;
    }
}
